<?php
	header('content-type:text/html;charset=utf-8'); 
	
	$dbdata = array();
	$i=0;
	
	$Order=$_GET["Order"];//字符串
	//从数据库中获取数据，为了节省内存，不要把数据一次性读到内存，从句柄中一行一行读即可 
	
	/* PDO Start */
	$dbName = "sqlsrv:Server=172.31.3.12,1433;Database=UFDATA_001_2017";//emc3030
	$dbUser = "sa";
	$dbPassword = "TDled!2018";
	$db = new PDO($dbName, $dbUser, $dbPassword);//這裡是PDO鏈接方法
	
	$sql = 
	"select 
		distinct binitem 
	from 
		ldx_creecompare 
	where 
		led 
	in
	(select 
		distinct cDefine28 
	from 
		DispatchLists 
	where 
		DLID 
	in 
	(select 
		DLID  
	from 
		DispatchList 
	where cDLCode='".$Order."'))";
	//"select distinct binitem from ldx_creecompare where led in(select distinct cDefine28 from DispatchLists where DLID in (select DLID  from DispatchList where cDLCode='".$Order."'))"
	
	
	$res = $db->query($sql);
	
	while ($row = $res->fetch()){
		//$i+=1;
		$dbdata[$i]=$row['binitem'];
		$i=$i+1;
		
	}
	
	//Print array in JSON format
	echo json_encode($dbdata);
	
?>
